package com.sinbad.produce.mqconfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * topic模式
 */
@Configuration
public class TopicConfigMQ {

    /***********************创建队列****************/
    @Bean(name = "topicQueueA")
    public Queue queueMessage() {
        return new Queue("topicQueue.A", true, false, false);
    }

    @Bean(name = "topicQueueB")
    public Queue queueMessages() {
        return new Queue("topicQueue.B", true, false, false);
    }

    /***********************创建Topic交换器****************/
    @Bean("topicExchange")
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange", true, false);
    }


    /***********************队列和交换器绑定****************/
    @Bean
    Binding bindingTopicQueueA(@Qualifier("topicQueueA") Queue queueMessage,
                               @Qualifier("topicExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message.test");
    }

    @Bean
    Binding bindingTopicQueueB(@Qualifier("topicQueueB") Queue queueMessages,
                               @Qualifier("topicExchange") TopicExchange exchange) {
        return BindingBuilder.bind(queueMessages).to(exchange).with("rabbitMQ.test.topic");
    }

}
